﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace planerka.DataAccess.DataService
{
    public class FileService
    {
        // очистить папку TEMP
        public static void emptyTempDirectory(string containsPattern = "")
        {
            string tempDirectory = System.Web.HttpContext.Current.Server.MapPath("~/temp/");
            System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(tempDirectory);
            // Get a reference to each file in that directory.
            System.IO.FileInfo[] fiArr = di.GetFiles();

            foreach (System.IO.FileInfo finfo in fiArr)
            {
                // проверим на соответствие шаблону
                if (containsPattern != "")
                {
                    if (!finfo.Name.Contains(containsPattern))
                        continue;
                }

                try
                {
                    System.IO.File.Delete(Path.Combine(finfo.FullName));
                }
                catch { }

            }
        }
    }
}
